<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\Common;

use App\Exception\BaseException;

class CheckHelper
{
    use Singleton;

    /**
     * Notes:手机号格式校验
     * Author:Jurij.cao
     * Date:2022/6/30
     * @param $mobile
     * @return bool
     */
    public function mobileCheck($mobile): bool
    {
        if (strlen($mobile) == 11 && preg_match('/^(1[3-9])\d{9}$/', $mobile)) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * Notes:密码格式校验并返回加密后密码
     * Author:Jurij.cao
     * Date:2022/6/30
     * @param $password
     * @return bool
     * @throws BaseException
     */
    public function passwordCheck($password): bool
    {
        if (strlen($password) < 8 ){
            return '';
        }

        if (!preg_match('^.*[a-z].*$',$password) || !!preg_match('^.*[A-Z].*$',$password)) {
            return '';
        }

        if (!preg_match('^.*[0-9].*$',$password))
        {
            return '';
        }

        return md5(md5($password));
    }


}

